/**
 * 
 */
package fpt.pits.form;

import java.util.ArrayList;
import java.util.List;

import javax.portlet.PortletSession;
import javax.portlet.RenderRequest;
import javax.portlet.RenderResponse;

import fpt.pits.util.Constants;

/**
 * This object uses to contain the value of Login.jsp form
 * @author yoyosakura
 * @version 1.0
 */
public class LoginInfoForm {
    /**
     * txtUserName property
     */
    private String txtUsername;
    /**
     * txtPassword property
     */
    private String txtPassword;
    /**
     * @param txtUserName the txtUserName to set
     */
    public void setTxtUsername(String txtUserName) {
        this.txtUsername = txtUserName;
    }
    /**
     * @return the txtUserName
     */
    public String getTxtUsername() {
        return txtUsername;
    }
    /**
     * @param txtPassword the txtPassword to set
     */
    public void setTxtPassword(String txtPassword) {
        this.txtPassword = txtPassword;
    }
    /**
     * @return the txtPassword
     */
    public String getTxtPassword() {
        return txtPassword;
    }
    /**
     * validate the input data
     * @param request
     * @param response
     * @return
     */
    public List<String> validate(RenderRequest request, RenderResponse response) {
        List<String> errorMessages = new ArrayList<String>();
        if (this.txtUsername.equals(Constants.BLANK_VALUE)) {
            errorMessages.add("Please enter your username!");
            
        } else {
            request.getPortletSession().setAttribute(
                    Constants.USERNAME_PORT_SESS_ATT, 
                    this.txtUsername,
                    PortletSession.APPLICATION_SCOPE);
        }
        if (this.txtPassword.equals(Constants.BLANK_VALUE)) {
            errorMessages.add("Please enter your password!");
        }
        return errorMessages;
    }
}
